import csv

import numpy as np
import pandas as pd
import torch
from matplotlib import pyplot as plt


# 数据的读取
def make_data1():
    data = pd.read_csv(r'../dataset/dataset.csv')
    X = data.Education.values.reshape(-1, 1)
    Y = data.Income.values.reshape(-1, 1)
    X = torch.from_numpy(X).type(torch.FloatTensor)
    Y = torch.from_numpy(Y).type(torch.FloatTensor)
    print(X)
    return X, Y


def make_data():
    points = []
    for i in range(300):
        x = round(np.random.uniform(0, 20), 2)
        noise = np.random.normal(0, 1)
        y = round(0.825 * x + noise, 2)
        points.append([x, y])
        plt.scatter(x, y, c='r')
    plt.show()

    print(points)
    with open('../dataset/data.csv', mode='a', newline='', encoding='utf-8-sig') as f:
        for p in points:
            csv_writer = csv.writer(f, delimiter=',')
            csv_writer.writerow(p)


def get_data():
    points = np.genfromtxt("../dataset/data.csv", skip_header=0, dtype=None, encoding="utf-8-sig")
    for p in points:
        plt.scatter(p.split(",")[0], p.split(",")[1], c='r')
    plt.show()


if __name__ == '__main__':
    # x, y = make_data()
    # print(x.shape)
    # print(x.type())
    # make_data()
    # get_data()
    make_data1()
    # print(make_data1())
